import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';

class ChildChatLogic extends GetxController {
  List<V2TimMessage> list = [];

  ScrollController scrollController = ScrollController();

  receiveMessage(V2TimMessage message) {
    list.add(message);
    _scrollToBottom();
    update();
  }

  void _scrollToBottom() {
    Future.delayed(Duration(milliseconds: 100), () {
      if (scrollController.hasClients) {
        // 平滑滚动到底部，延时调整
        scrollController.animateTo(
          scrollController.position.maxScrollExtent,
          duration: Duration(milliseconds: 300), // 设定动画持续时长
          curve: Curves.easeInOut, // 使用平滑的滚动曲线
        );
      }
    });
  }
}
